﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.EHR.Library;
using ZX.BLL.Extend;
using ZX.Web.UI.Controls;
using System.Data;
using ZX.DAL.DBExtend;
using System.Text;
using Newtonsoft.Json;

namespace ZX.WebApp.DeskTop
{
    public partial class main : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                CreateHtml();
        }
        private void CreateHtml()
        {
            //获取模块具体栏位布局信息
            //获取模块具体栏位布局信息
            DataSet ds = new DataSet();
            string strsql = @"
                            select a.*,b.DeskTopName,b.Height,b.Src,b.PageType from SysUserDesktop a,SysRoleDesktop b 
                            where a.RoleDesktopID=b.RoleDesktopID ";
            strsql += " and a.AddUser='" + this.UserId + "' order by a.Sort asc";
            DbSql execsql = new DAL.DBExtend.DbSql();
            ds = execsql.Query(strsql);

            StringBuilder sbCenter = new StringBuilder();
            StringBuilder sbRight = new StringBuilder();
            string frmStr = string.Empty;
            List<DeskHelpModel> listM = new List<DeskHelpModel>();

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                sbCenter.Append("<div class='center' id='domCenter'>");
                sbRight.Append("<div class='right' id='domRight'>");
                int b=0;
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    string sbHtml = string.Empty;
                    sbHtml +="<div class='mo' id='"+row["UserDesktopID"].ToString()+"' sort=" + row["Sort"].ToString() + " itemname=" + row["DeskTopName"].ToString() + ">";
                    sbHtml +="<h1><span><img src='../Images/icon/hr.gif' />";
                    sbHtml +=row["DeskTopName"].ToString();
                    sbHtml +="</span><font ><img name='imgShow' src='../Images/icon/collapse.gif'  onClick='doShow(this);'/></font></h1>";
                    sbHtml +="<div class='nr'";
                    if (row["Height"].ToString().Trim() != "")
                    {
                        string height = row["Height"].ToString().IndexOf("px") != -1 ? row["Height"].ToString() : row["Height"].ToString() + "px;";
                        sbHtml +=" style='height:" + height + "'";
                    }
                    sbHtml += "  >";
                    sbHtml += "<div id='f_" + row["UserDesktopID"].ToString() + "' style='width:85px;height:25px;float:right;font-size:10px;color:Red;'><img src='../Scripts/JQuery_zTree_v3.3/css/zTreeStyle/img/loading.gif' />&nbsp;&nbsp;加载中......</div>";
                    sbHtml += " <div id='data_" + row["UserDesktopID"].ToString() + "' style='width:100%;height:100%; padding-top:10px;'></div>";
                    sbHtml +="</div></div>";

                    string region = row["Region"].ToString().Trim().ToLower();
                    switch (region)
                    {
                        case "center": sbCenter.Append(sbHtml); break;
                        case "right": sbRight.Append(sbHtml); break;
                    }
                   // string key = Guid.NewGuid().ToString() + "_" + b;
                    b++;
                    //ClientScript.RegisterClientScriptBlock(this.GetType(), key, "<script type='text/javascript'>GetReportData('" + row["SRC"].ToString() + "','" + row["UserDesktopID"].ToString() + "')</script>");
                    //frmStr += row["UserDesktopID"].ToString() + "|" + row["Src"].ToString()+",";
                    DeskHelpModel m = new DeskHelpModel
                    {
                        SRC = row["SRC"].ToString(),
                        UserDesktopID = row["UserDesktopID"].ToString(),
                        PageType = row["PageType"].ToString()
                    };
                    listM.Add(m);
                }
               // if (frmStr.EndsWith(",")) frmStr = frmStr.Substring(0, frmStr.Length - 1);
                sbCenter.Append("</div>");
                sbRight.Append("</div>");
            }
            frmHide.Value = frmStr;
            lblContent.Text = sbCenter.ToString() + sbRight.ToString();

            string json = string.Empty;
            json = JsonConvert.SerializeObject(listM);
            ClientScript.RegisterClientScriptBlock(this.GetType(), "done", "<script type='text/javascript'>Execution(" + json + ")</script>");
        }
    }

    public class DeskHelpModel {
        public string SRC { get; set; }
        public string UserDesktopID { get; set; }
        public string PageType { get; set; }
    }
}